package top.ytazwc.principle.dependencyinversion.improve;

/**
 * @author 花木凋零成兰
 * @title DependencyInversion
 * @date 2024/4/16 17:09
 * @package top.ytazwc.principle.dependencyinversion.improve
 * @description 方案2
 */
public class DependencyInversion {
    public static void main(String[] args) {
        // 客户端无需改变
        Person person = new Person();
        person.receive(new Email());
        person.receive(new WeiXin());
    }
}
// 定义接口
interface IReceiver {
    public String getInfo();
}
// 电子邮件
class Email implements IReceiver {
    @Override
    public String getInfo() {
        return "电子邮件信息: hello world!";
    }
}
// 微信
class WeiXin implements IReceiver {
    @Override
    public String getInfo() {
        return "微信信息: hello world!";
    }
}
// 完成Person接收消息的功能
// 方式1完成
class Person {
    public void receive(IReceiver receiver) {
        System.out.println(receiver.getInfo());
    }
}